package com.hee.erp.modules.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hee.erp.modules.entity.SysUserContract;
import com.hee.erp.modules.entity.SysUserIdcard;
import com.hee.erp.modules.mapper.SysUserIdcardMapper;
import com.hee.erp.modules.service.ISysUserIdcardService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author weizehong
 * @since 2022-03-06
 */
@Service
@Transactional
public class SysUserIdcardServiceImpl extends ServiceImpl<SysUserIdcardMapper, SysUserIdcard> implements ISysUserIdcardService {

    @Override
    public List<SysUserIdcard> listByUserId(String userId) {

        LambdaQueryWrapper<SysUserIdcard> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysUserIdcard::getUserId,userId);
        return this.list(queryWrapper);
    }

    @Override
    public List<SysUserIdcard> saveUserIdcards(List<SysUserIdcard> list) {

        for (SysUserIdcard sysUserIdcard : list) {
            if (sysUserIdcard.getId().contains("-")) {
                //新增
                sysUserIdcard.setId(null);
                this.save(sysUserIdcard);
            } else {
                //修改
                this.updateById(sysUserIdcard);
            }
        }

        return list;
    }
}
